package com.company.secondary;

import java.util.*;

public class LK56 {
    public static void main(String[] args) {
        HashMap<Integer,Integer> map = new HashMap<>();
        Deque<Integer> deque = new LinkedList<>();

    }
    public static int[][] merge(int[][] intervals) {
        List<int[]> list = new ArrayList<>();
        list.add(intervals[0]);
        for(int i=1;i<intervals.length;i++) {
            int[] temp = list.remove(list.size() - 1);
            if (temp[1] < intervals[i][0]) {
                list.add(temp);
                list.add(intervals[i]);

            }
        }


        int[][] arr = new int[list.size()][2];
        for(int i =0;i<list.size();i++){
            int[] temp = list.get(i);
            arr[i][0] = temp[0];
            arr[i][1] = temp[1];
        }
        return arr;

    }
}
